package com.caine.androidtask.ls16;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;

public class SmsContent {
	private Activity activity;
	private Uri uri;
	private List<SmsInfo> list;

	public SmsContent(Uri uri) {
		this.uri = uri;
		list = new ArrayList<SmsInfo>();
	}

	public List<SmsInfo> getSmsInfo() {
		String[] projection = new String[] { "_id", "address", "person",
				"body", "date", "type" };
		Cursor cursor = activity.managedQuery(uri, projection, null, null,
				"date desc");
		
		int nameColumn = cursor.getColumnIndex("person");
		int phoneNumberColumn = cursor.getColumnIndex("address");
		int smsbodyColumn = cursor.getColumnIndex("body");
		int dateColumn = cursor.getColumnIndex("date");
		int typeColumn = cursor.getColumnIndex("type");
		while (cursor.moveToNext()) {
			SmsInfo info = new SmsInfo();
			info.setName(cursor.getString(nameColumn));
			info.setPhoneNumber(cursor.getString(phoneNumberColumn));
			info.setSmsBody(cursor.getString(smsbodyColumn));
			info.setDate(cursor.getString(dateColumn));
			info.setType(cursor.getInt(typeColumn));
			list.add(info);
		}
		cursor.close();
		return list;
	}
}
